package com.shanzmoo.merchant.manage.api.manager;

import cn.hutool.core.lang.UUID;
import cn.hutool.crypto.digest.MD5;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.util.CollectionUtil;
import com.shanzmoo.base.util.RedisUtil;
import com.shanzmoo.core.manager.base.AliSmsManager;
import com.shanzmoo.db.module.member.domain.dto.*;
import com.shanzmoo.db.module.member.domain.query.*;
import com.shanzmoo.db.module.member.domain.vo.*;
import com.shanzmoo.db.module.member.entity.*;
import com.shanzmoo.db.module.member.service.*;
import com.shanzmoo.db.module.merchant.entity.MerchantInfoEntity;
import com.shanzmoo.db.module.merchant.service.IMerchantInfoService;
import com.shanzmoo.db.util.RandomUtil;
import com.shanzmoo.merchant.manage.api.domain.AuthUser;
import com.shanzmoo.merchant.manage.api.util.SecurityUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class MemberMerchantManager {

    @Autowired
    private IMemberInfoService memberInfoService;
    @Autowired
    private IMemberMerchantService memberMerchantService;
    @Autowired
    private IMemberAccountRecordService memberAccountRecordService;
    @Autowired
    private IMemberAccountScoreRecordService memberAccountScoreRecordService;
    @Autowired
    private IMemberCardConfigService memberCardConfigService;
    @Autowired
    private IMemberCardConfigDetailService memberCardConfigDetailService;
    @Autowired
    private IMemberActivityConfigService activityConfigService;
    @Autowired
    private IMemberActivityConfigDetailService activityConfigDetailService;
    @Autowired
    private IMemberCouponConfigService couponConfigService;
    @Autowired
    private AliSmsManager aliSmsManager;
    @Autowired
    private IMerchantInfoService merchantInfoService;

    public SHttpResponse<PageRespBase<MemberMerchantVO>> getMemberMerchantListPage(MemberQuery query) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        query.setMerchantCode(currentMerchantCode);

        String nickname = query.getNickname();
        String mobile = query.getMobile();
        String startTime = query.getStartTime();
        String endTime = query.getEndTime();
        String merchantCode = query.getMerchantCode();
        Page<MemberMerchantEntity> page = memberMerchantService.page(
                query.page(),
                new LambdaQueryWrapper<MemberMerchantEntity>()
                        .like(StringUtils.isNotEmpty(nickname), MemberMerchantEntity::getNickname, "%" + nickname + "%")
                        .eq(StringUtils.isNotEmpty(mobile), MemberMerchantEntity::getMobile, mobile)
                        .between(StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime), MemberMerchantEntity::getCreateTime, startTime, endTime)
                        .eq(StringUtils.isNotEmpty(merchantCode),MemberMerchantEntity::getMerchantCode,merchantCode)
                        .orderByDesc(MemberMerchantEntity::getId)
        );
        List<MemberMerchantVO> reList = CollectionUtil.convert(page.getRecords(), MemberMerchantVO.class);
        PageRespBase<MemberMerchantVO> re = PageRespBase.create(page,reList);
        return SHttpResponse.ok(re);
    }

    /**
     * 商户会员详情
     * @param id
     * @return
     */
    public SHttpResponse<MemberMerchantDetailVO> getMemberMerchantDetail(Integer id) {
        MemberMerchantDetailVO memberMerchantDetailVO = new MemberMerchantDetailVO();
        MemberMerchantEntity memberMerchant = memberMerchantService.getById(id);
        BeanUtils.copyProperties(memberMerchant,memberMerchantDetailVO);
        //查询流水表中该用户的流水
        List<MemberAccountRecordEntity> recordList = memberAccountRecordService.getbyMemberMerchantId(id);
        if (CollectionUtils.isEmpty(recordList)){
            //流水表没记录直接返回
            return SHttpResponse.ok(memberMerchantDetailVO);
        }
        List<MemberAccountRecordEntity> rechargeList = recordList.stream().filter(a -> a.getType() == 1).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(rechargeList)){
            memberMerchantDetailVO.setRechargeAmt(rechargeList.stream().mapToLong(MemberAccountRecordEntity::getAmount).sum());
            memberMerchantDetailVO.setRechargeCount(rechargeList.size());
            //todo 累计优惠
            memberMerchantDetailVO.setRechargeDiscountTotal(null);
        }
        List<MemberAccountRecordEntity> resumeList = recordList.stream().filter(a -> a.getType() == 2).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(resumeList)){
            memberMerchantDetailVO.setResumeAmt(resumeList.stream().mapToLong(MemberAccountRecordEntity::getAmount).sum());
            memberMerchantDetailVO.setResumeCount(resumeList.size());
            //todo 累计优惠
            memberMerchantDetailVO.setResumeDiscountTotal(null);
        }
        return SHttpResponse.ok(memberMerchantDetailVO);
    }

    public SHttpResponse<PageRespBase<MemberAccountRecordVO>> getMemberMerchantTransList(MemberMerchantIdPageQuery request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        MemberMerchantEntity memberMerchant = memberMerchantService.getById(request.getId());
        if (memberMerchant == null){
            return SHttpResponse.fail(200001,"商户会员不存在");
        }
        if (StringUtils.isEmpty(memberMerchant.getMerchantCode()) || (!memberMerchant.getMerchantCode().equals(currentMerchantCode))){
            return SHttpResponse.fail(200002,"无权查看");
        }
        MemberAccountPageQuery query = new MemberAccountPageQuery();
        query.setMemberMerchantId(request.getId());
        IPage<MemberAccountRecordVO> memberAccountRecordVOIPage = memberAccountRecordService.queryByRequest(query);
        PageRespBase<MemberAccountRecordVO> re = PageRespBase.create(memberAccountRecordVOIPage, memberAccountRecordVOIPage.getRecords());
        return SHttpResponse.ok(re);
    }

    /**
     * 积分变动记录
     * @param request
     * @return
     */
    public SHttpResponse<PageRespBase<MemberAccountScoreRecordVO>> getMemberMerchantScoreList(MemberMerchantIdPageQuery request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        MemberMerchantEntity memberMerchant = memberMerchantService.getById(request.getId());
        if (memberMerchant == null){
            return SHttpResponse.fail(200001,"商户会员不存在");
        }
        if (StringUtils.isEmpty(memberMerchant.getMerchantCode()) || (!memberMerchant.getMerchantCode().equals(currentMerchantCode))){
            return SHttpResponse.fail(200002,"无权查看");
        }
        Page<MemberAccountScoreRecordEntity> page = memberAccountScoreRecordService.getbyMemberIdPage(request);
        List<MemberAccountScoreRecordVO> reList = CollectionUtil.convert(page.getRecords(), MemberAccountScoreRecordVO.class);
        PageRespBase<MemberAccountScoreRecordVO> re = PageRespBase.create(page,reList);
        return SHttpResponse.ok(re);
    }

    public static void main(String[] args) {
        String aaaa = MD5.create().digestHex("AAAA");
        System.out.println(aaaa);
    }
    /**
     * 会员卡配置保存
     * @param request
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public SHttpResponse<Boolean> saveCardConfig(MemberCardConfigDTO request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }

        String password = request.getPassword();
        List<MemberCardConfigDetailDTO> cardConfigDetail = request.getCardConfigDetail();
        if (CollectionUtils.isEmpty(cardConfigDetail) || cardConfigDetail.size()!=3){
            //todo 规则校验
            return SHttpResponse.fail(21113,"默认金额必填写，依次递增,赠送金额要不全部填写，要不都不填写，依次递增,赠送金额为空的时候，是否引导会员充值为否");
        }
        String bakVerifyCode = RedisUtil.get("MEMBER_CARD_CONFIG_" + currentUser.getUserId());
        if (StringUtils.isEmpty(bakVerifyCode) || !request.getVerifyCode().equals(bakVerifyCode)){
            return SHttpResponse.fail(21114,"验证码错误");
        }
        //一个商户只有一个会员卡管理，所以每次都是覆盖
        MemberCardConfigEntity saveMemberConfig = new MemberCardConfigEntity();
        MemberCardConfigEntity memberCardConfigEntity = memberCardConfigService.getbyMerchantCode(currentMerchantCode);
        if (memberCardConfigEntity != null){
            saveMemberConfig.setId(memberCardConfigEntity.getId());
            memberCardConfigDetailService.deleteByConfigId(memberCardConfigEntity.getId());
        }
        request.createEntity(saveMemberConfig);
        if (!StringUtils.isEmpty(request.getPassword())){
            //输入的密码不为空则保存密码
            saveMemberConfig.setPassword(MD5.create().digestHex(request.getPassword()));
        }else {
            saveMemberConfig.setPassword(null);
        }
        saveMemberConfig.setMerchantCode(currentMerchantCode);
        saveMemberConfig.setCreateUser(currentUser.getUserId());
        memberCardConfigService.saveOrUpdate(saveMemberConfig);

        List<MemberCardConfigDetailEntity> collect = cardConfigDetail.stream().map(a -> {
            MemberCardConfigDetailEntity saveMemberConfigDetail = new MemberCardConfigDetailEntity();
            saveMemberConfigDetail.setCardConfigId(saveMemberConfig.getId());
            saveMemberConfigDetail.setGiveAmt(a.getGiveAmt());
            saveMemberConfigDetail.setDefaultAmt(a.getDefaultAmt());
            saveMemberConfigDetail.setCreateUser(currentUser.getUserId());
            return saveMemberConfigDetail;
        }).collect(Collectors.toList());

        memberCardConfigDetailService.saveBatch(collect);

        return SHttpResponse.ok(true);
    }

    public SHttpResponse<MemberCardConfigDTO> cardConfigDetail() {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        MemberCardConfigDTO memberCardConfigDTO = new MemberCardConfigDTO();
        MemberCardConfigEntity memberCardConfigEntity = memberCardConfigService.getbyMerchantCode(currentMerchantCode);
        if (memberCardConfigEntity!=null){
            memberCardConfigEntity.setPassword(null);
            BeanUtils.copyProperties(memberCardConfigEntity,memberCardConfigDTO);
            List<MemberCardConfigDetailEntity> details =memberCardConfigDetailService.getbyConfigId(memberCardConfigEntity.getId());
            if (!CollectionUtils.isEmpty(details)){
                List<MemberCardConfigDetailDTO> collect = details.stream().map(a -> {
                    MemberCardConfigDetailDTO detailDTO = new MemberCardConfigDetailDTO();
                    detailDTO.setCardConfigId(a.getCardConfigId());
                    detailDTO.setDefaultAmt(a.getDefaultAmt());
                    detailDTO.setGiveAmt(a.getGiveAmt());
                    return detailDTO;
                }).collect(Collectors.toList());
                memberCardConfigDTO.setCardConfigDetail(collect);
            }
        }
        return SHttpResponse.ok(memberCardConfigDTO);
    }

    /**
     * 会员活动 分页列表
      * @param request
     * @return
     */
    public SHttpResponse<PageRespBase<MemberActivityConfigVO>> getActivityList(MemberActivityPageQuery request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        request.setMerchantCode(currentMerchantCode);
        Page<MemberActivityConfigEntity> page = activityConfigService.getByPage(request);
        List<MemberActivityConfigVO> convert = CollectionUtil.convert(page.getRecords(), MemberActivityConfigVO.class);
        PageRespBase<MemberActivityConfigVO> re = PageRespBase.create(page,convert);
        return SHttpResponse.ok(re);
    }

    public SHttpResponse<MemberActivityConfigVO> getActivityDetail(Integer id) {
        MemberActivityConfigVO response = new MemberActivityConfigVO();
        MemberActivityConfigEntity activityConfig = activityConfigService.getById(id);
        if (activityConfig != null){
            BeanUtils.copyProperties(activityConfig,response);
            List<MemberActivityConfigDetailEntity> activityConfigDetails =  activityConfigDetailService.getbyActivityConfigId(id);
            if (!CollectionUtil.isEmpty(activityConfigDetails)){
                List<MemberActivityConfigDetailVO> reList = CollectionUtil.convert(activityConfigDetails, MemberActivityConfigDetailVO.class);
                response.setActivityDetail(reList);
            }
        }

        return SHttpResponse.ok(response);
    }

    /**
     * 会员活动保存
     * @param request
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public SHttpResponse<Boolean> saveActivity(MemberActivityConfigVO request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        Integer id = request.getId();
        MemberActivityConfigEntity saveConfig = new MemberActivityConfigEntity();
        BeanUtils.copyProperties(request,saveConfig);
        if (id!=null){
            MemberActivityConfigEntity activityConfigEntity = activityConfigService.getById(id);
            if (activityConfigEntity == null){
                return SHttpResponse.fail(200003,"编辑数据不存在");
            }
            if (!activityConfigEntity.getMerchantCode().equals(currentMerchantCode)){
                return SHttpResponse.fail(200002,"无权限");
            }
            saveConfig.setId(id);
            //编辑时，先删除明细
            activityConfigDetailService.deleteByConfigId(id);
        }else {
            saveConfig.setCreateUser(currentUser.getUserId());
        }
        saveConfig.setMerchantCode(currentMerchantCode);
        saveConfig.setUpdateUser(currentUser.getUserId());
        activityConfigService.saveOrUpdate(saveConfig);
        List<MemberActivityConfigDetailVO> activityDetail = request.getActivityDetail();
        if (!CollectionUtil.isEmpty(activityDetail)){
            List<MemberActivityConfigDetailEntity> convert = CollectionUtil.convert(activityDetail, MemberActivityConfigDetailEntity.class);
            convert.forEach(a->a.setAcivityId(saveConfig.getId()));
            activityConfigDetailService.saveBatch(convert);
        }
        return SHttpResponse.ok(true);
    }

    public SHttpResponse<PageRespBase<MemberCouponConfigVO>> getCouponList(MemberCouponConfigPageQuery request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        request.setMerchantCode(currentMerchantCode);
        IPage<MemberCouponConfigEntity> list = couponConfigService.queryByPage(request);
        List<MemberCouponConfigVO> convert = CollectionUtil.convert(list.getRecords(), MemberCouponConfigVO.class);
        PageRespBase<MemberCouponConfigVO> re = PageRespBase.create(list,convert);
        //todo 发放数量，核销数量
        return SHttpResponse.ok(re);
    }

    public SHttpResponse<MemberCouponConfigVO> getCouponDetail(Integer id) {
        MemberCouponConfigEntity memberCouponConfigEntity = couponConfigService.getById(id);
        MemberCouponConfigVO res = new MemberCouponConfigVO();
        BeanUtils.copyProperties(memberCouponConfigEntity,res);
        return SHttpResponse.ok(res);
    }
    @Transactional(rollbackFor = Exception.class)
    public SHttpResponse<Boolean> saveCouponConfig(MemberCouponConfigVO request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        MemberCouponConfigEntity saveOrUpdate = new MemberCouponConfigEntity();
        BeanUtils.copyProperties(request,saveOrUpdate);
        Integer id = request.getId();
        if (id!=null){
            MemberCouponConfigEntity memberCouponConfigEntity = couponConfigService.getById(id);
            if (memberCouponConfigEntity == null){
                return SHttpResponse.fail(200003,"数据不存在");
            }
            if (!memberCouponConfigEntity.getMerchantCode().equals(currentMerchantCode)){
                return SHttpResponse.fail(200002,"无权限");
            }
            saveOrUpdate.setId(id);
        }else {
            saveOrUpdate.setCreateUser(currentUser.getUserId());
        }
        saveOrUpdate.setMerchantCode(currentMerchantCode);
        saveOrUpdate.setUpdateUser(currentUser.getUserId());
        couponConfigService.saveOrUpdate(saveOrUpdate);
        return SHttpResponse.ok(true);
    }

    /**
     * 平台充值，直接插入流水表，增加账户余额
     * @param request
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public SHttpResponse<Boolean> merchantMemberRecharge(MemberMerchantRechargeDTO request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        MemberCardConfigEntity CurrentMemberCardConfig = memberCardConfigService.getbyMerchantCode(currentMerchantCode);
        if (CurrentMemberCardConfig==null || !MD5.create().digestHex(request.getPassword()).equals(CurrentMemberCardConfig.getPassword())){
            return SHttpResponse.fail(21112,"密码错误");
        }

        MemberMerchantEntity memberMerchant = memberMerchantService.getById(request.getId());
        if (memberMerchant == null){
            return SHttpResponse.fail(200001,"商户会员不存在");
        }
        MemberMerchantEntity memberMerchantEntity = new MemberMerchantEntity();
        memberMerchantEntity.setId(request.getId());
        memberMerchantEntity.setBalance(memberMerchant.getBalance()+request.getAmount());
        memberMerchantService.updateById(memberMerchantEntity);
        //商户平台充值，直接增加账户余额
        MemberAccountRecordEntity memberAccountRecordEntity = new MemberAccountRecordEntity();
        memberAccountRecordEntity.setShopCode(request.getShopCode());
        memberAccountRecordEntity.setType(3);
        //平台充值，没有订单，流水号随机生成，
        memberAccountRecordEntity.setAmount(request.getAmount());
        memberAccountRecordEntity.setOrderNo(UUID.fastUUID().toString().substring(0,32));
        memberAccountRecordEntity.setDiscountFlag(false);
        memberAccountRecordEntity.setOrderTime(LocalDateTime.now());
        memberAccountRecordEntity.setMemberMerchantId(request.getId());
        memberAccountRecordEntity.setCurrentBalance(memberMerchantEntity.getBalance());
        memberAccountRecordService.save(memberAccountRecordEntity);
        return SHttpResponse.ok(true);
    }

    /**
     * 核销，直接减余额
     * @param request
     * @return
     */
    public SHttpResponse<Boolean> merchantMemberVerify(MemberMerchantVerifyDTO request) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        MemberCardConfigEntity CurrentMemberCardConfig = memberCardConfigService.getbyMerchantCode(currentMerchantCode);

        if (CurrentMemberCardConfig==null || !MD5.create().digestHex(request.getPassword()).equals(CurrentMemberCardConfig.getPassword())){
            return SHttpResponse.fail(21112,"密码错误");
        }
        MemberMerchantEntity memberMerchant = memberMerchantService.getById(request.getId());
        if (memberMerchant == null){
            return SHttpResponse.fail(200001,"商户会员不存在");
        }
        MemberMerchantEntity memberMerchantEntity = new MemberMerchantEntity();
        memberMerchantEntity.setId(request.getId());
        memberMerchantEntity.setBalance(memberMerchant.getBalance()-request.getAmount());
        //todo 乐观锁，
        memberMerchantService.updateById(memberMerchantEntity);
        //商户平台充值，直接增加账户余额
        MemberAccountRecordEntity memberAccountRecordEntity = new MemberAccountRecordEntity();
        memberAccountRecordEntity.setType(4);
        //平台充值，没有订单，流水号随机生成，
        memberAccountRecordEntity.setAmount(request.getAmount());
        memberAccountRecordEntity.setOrderNo(UUID.fastUUID().toString().substring(0,32));
        memberAccountRecordEntity.setDiscountFlag(false);
        memberAccountRecordEntity.setOrderTime(LocalDateTime.now());
        memberAccountRecordEntity.setMemberMerchantId(request.getId());
        memberAccountRecordEntity.setCurrentBalance(memberMerchantEntity.getBalance());
        memberAccountRecordService.save(memberAccountRecordEntity);

        return SHttpResponse.ok(true);
    }

    /**
     * 会员状态修改
     * @param request
     * @return
     */
    public SHttpResponse<Boolean> memberMerchantStatusChange(MemberMerchantStatusChangeDTO request) {
        MemberMerchantEntity memberMerchant = memberMerchantService.getById(request.getId());
        if (memberMerchant == null){
            return SHttpResponse.fail(200001,"商户会员不存在");
        }
        MemberMerchantEntity memberMerchantEntity = new MemberMerchantEntity();
        memberMerchantEntity.setId(memberMerchant.getId());
        memberMerchantEntity.setStatus(request.getStauts());
        memberMerchantService.updateById(memberMerchantEntity);
        return SHttpResponse.ok(true);
    }

    /**
     * 删除优惠券配置
     * @param id
     * @return
     */
    public SHttpResponse<Boolean> deleteCouponConfig(Integer id) {
        couponConfigService.deleteById(id);
        return SHttpResponse.ok(true);
    }

    /**
     * 删除活动配置
     * @param id
     * @return
     */
    public SHttpResponse<Boolean> deleteActivityConfig(Integer id) {
        MemberActivityConfigEntity activityConfigEntity = activityConfigService.getById(id);
        if (activityConfigEntity == null){
            return SHttpResponse.fail(200003,"数据不存在");
        }
        activityConfigService.removeById(id);
        activityConfigDetailService.deleteByConfigId(id);
        return SHttpResponse.ok(true);
    }

    public SHttpResponse<Boolean> cardConfigDelete(Integer id) {
        AuthUser currentUser = SecurityUtil.getCurrentUser();
        String currentMerchantCode = currentUser.getMerchantCode();
        if (StringUtils.isEmpty(currentMerchantCode)){
            return SHttpResponse.fail(21111,"当前登录人商户code为空");
        }
        memberCardConfigService.getById(id);
        return null;
    }

    public SHttpResponse<Boolean> sendSmsMsg() {
        Integer currentUserId = SecurityUtil.getCurrentUserId();
        String merchantCode = SecurityUtil.getCurrentUser().getMerchantCode();
        MerchantInfoEntity merchantInfoEntity = merchantInfoService.getByMerchantCode(merchantCode);
        if (merchantInfoEntity == null){
            return SHttpResponse.fail(33211,"商户配置不存在");
        }
        String mobile = merchantInfoEntity.getMobile();
        if (StringUtils.isEmpty(mobile)){
            return SHttpResponse.fail(33211,"商户手机号未配置");
        }
        // 1、构建验证码信息并存入缓存
        String code = RandomUtil.createRandom(false, 6);
        // 2、存入缓存(10分钟有效)
        RedisUtil.set("MEMBER_CARD_CONFIG_"+currentUserId, code, 10l);
        // 3、发送验证短信
        aliSmsManager.sendLoginSms(mobile, code);
        return SHttpResponse.ok();
    }
}
